package com.group.three.controller.order;

import com.group.three.entity.OrderComplaint;
import com.group.three.entity.OrderComplaintVO;
import com.group.three.service.OrderComplaintService;
import com.group.three.untils.SnowFlakeUtil;
import com.group.three.vo.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺端,交易投诉接口
 **/
@RestController
@Api(tags = "店铺端,交易投诉接口")
@RequestMapping("/store/order/complain")
public class OrderComplaintStoreController {
    /**
     * 交易投诉
     */
    @Autowired
    private OrderComplaintService orderComplaintService;

    @ApiOperation(value = "分页获取")
    @GetMapping
    public JsonResult get(int pageNum, int pageSize) {

        List<OrderComplaint> orderComplaints = orderComplaintService.getOrderComplainByPage(pageNum, pageSize);
        if (orderComplaints != null) {
            return new JsonResult("200", "交易投诉列表查询成功", orderComplaints);
        }
        return new JsonResult("400", "交易投诉列表查询失败");
    }

    @ApiOperation(value = "获取投诉单详情")
    @ApiImplicitParam(name = "id", value = "投诉单ID", required = true, paramType = "path")
    @GetMapping(value = "/{id}")
    public JsonResult get(@PathVariable String id) {
        OrderComplaintVO orderComplaintItem = orderComplaintService.getOrderComplainById(id);
        if (orderComplaintItem != null) {
            return new JsonResult("200", "投诉单详情列表查询成功", orderComplaintItem);
        }
        return new JsonResult("400", "投诉单详情列表查询失败");
    }

    @ApiOperation(value = "添加交易投诉对话")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "complainId", value = "投诉单ID", required = true, paramType = "query"),
            @ApiImplicitParam(name = "content", value = "内容", required = true, paramType = "query")
    })
    @PostMapping("/communication")
    public JsonResult addCommunication(@RequestParam String complainId, @RequestParam String content,@RequestParam String ownerId) {
        String s = String.valueOf(SnowFlakeUtil.getSnowFlakeId());
        String substring = s.substring(0, s.length() - 3);
        int i = orderComplaintService.addCommunication(complainId, content,ownerId,substring);
        if (i == 1) {
            return new JsonResult("200", "添加交易投诉成功");
        }
        return new JsonResult("400", "添加交易投诉失败");
    }
}
